<template>
  <!-- 最简横柱状图 -->
  <div style="height:280px;width:100%;overflow: hidden;">
    <Row
      v-if="option.series.length==0"
      style="height:280px;background: white;"
      type="flex"
      align="middle"
      justify="center"
    >
      <img src="~@/assets/img/efficiencyAnalysis/zwsj.png" height="50%" />
    </Row>
    <div ref="main" style="overflow: hidden;height:280px;"></div>
  </div>
</template>

<script>
import { Style } from "./echartsStyle.js";
export default {
  props: {
    viewData: {
      type: Object,
      default: null
    },
    nameLocation: {
      type: String,
      default: "end"
    }
  },
  data() {
    return {
      option: {
        noDataLoadingOption: {
          text: "暂无数据",
          effect: "bubble",
          effectOption: {
            effect: {
              n: 0
            }
          }
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow"
          }
        },
        grid: {
          top: "10%",
          bottom: "10%",
          left: "22%",
          right: "6%"
        },
        color: Style.color,
        // xAxis: {
        //   name: this.viewData != null ? this.viewData.xName : "",
        //   nameTextStyle: {
        //     color: "#666",
        //     padding: [0, 0, 550, -50]
        //   },
        //   type: "value"
        // },
        xAxis: {
          show: true,
          name: this.viewData != null ? this.viewData.xName : "",
          type: "value",
          data: this.viewData != null ? this.viewData.xData : [],
          nameTextStyle: {
            padding: [27, 0, 0, 0],
            color: '#666' //x轴单位的颜色
          },
          axisLine: {
            show: false, //x轴,测试要求加上
            lineStyle: {
              type: "solid",
              color: "#e8e8e8" //x轴线的颜色
            }
          },
          axisLabel: {
            color: "#666" //x轴文字的颜色
          },
          axisTick: {
            show: false //测试要求不显示刻度线
          },
          splitLine: {
            show: true,
            lineStyle: {
              type: "dashed",
              color: "#e8e8e8"
            }
          },
        },
        yAxis: {
          type: "value",
          
          nameTextStyle: {
            padding: [0, 0, 0, -33],
            color: "#666" //x轴单位的颜色
          },
          axisLine: {
            show: true, //x轴,测试要求加上
            lineStyle: {
              type: "solid",
              color: "#e8e8e8" //x轴线的颜色
            }
          },
          axisLabel: {
            color: "#666" //x轴文字的颜色
          },
          axisTick: {
            show: false //测试要求不显示刻度线
          },
          name: this.viewData != null ? this.viewData.yName : "",
          nameLocation: this.nameLocation,
          type: "category",
          data: this.viewData != null ? this.viewData.yData : []
        },
        series: this.viewData != null ? this.viewData.sData : []
      }
    };
  },
  computed: {},
  watch: {
    viewData(value) {
      if ("yName" in value) {
        this.option.yAxis.name = value.yName;
      } else {
        this.viewData.yName = "";
      }
      if ("xName" in value) {
        this.option.xAxis.name = value.xName;
      } else {
        this.viewData.xName = "";
      }
      if ("color" in value) {
        this.option.color = value.color;
      } else {
        this.option.color = "";
      }
      // if ("nameLocation" in value) {
      //   this.option.xAxis.nameLocation = value.nameLocation;
      // } else {
      //   this.viewData.xName = "end";
      // }

      this.option.yAxis.data = value.yData;
      this.option.series = value.sData;
      let myChart = this.$echarts.init(this.$refs.main);
      myChart.setOption(this.option, true);
    }
  },
  methods: {},
  created() {},
  mounted() {
    let myChart = this.$echarts.init(this.$refs.main);
    myChart.setOption(this.option);
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {} // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
</style>
